<Window x:Class="ThScoreFileConverter.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:mdb="clr-namespace:MvvmDialogBehavior;assembly=MvvmDialogBehavior"
        xmlns:a="clr-namespace:ThScoreFileConverter.Actions"
        xmlns:b="clr-namespace:ThScoreFileConverter.Behaviors"
        xmlns:prop="clr-namespace:ThScoreFileConverter.Properties"
        xmlns:vm="clr-namespace:ThScoreFileConverter.ViewModels"
        IsEnabled="{Binding IsIdle}"
        ResizeMode="CanMinimize"
        SizeToContent="WidthAndHeight"
        Style="{StaticResource WindowStyleKey}"
        Title="{Binding Title}"
        UseLayoutRounding="True">

    <Window.DataContext>
        <vm:MainWindowViewModel/>
    </Window.DataContext>

    <i:Interaction.Behaviors>
        <mdb:DialogBehavior Content="{Binding AboutWindowViewModel}"
                            Owner="{Binding MainWindow, Source={x:Static Application.Current}}"
                            WindowStartupLocation="CenterOwner">
            <mdb:DialogBehavior.Style>
                <Style BasedOn="{StaticResource DialogStyleKey}"
                       TargetType="{x:Type Window}">
                    <Setter Property="Title"
                            Value="{Binding Content.Title, RelativeSource={x:Static RelativeSource.Self}}"/>
                </Style>
            </mdb:DialogBehavior.Style>
        </mdb:DialogBehavior>
        <mdb:DialogBehavior Content="{Binding SettingWindowViewModel}"
                            Owner="{Binding MainWindow, Source={x:Static Application.Current}}"
                            WindowStartupLocation="CenterOwner">
            <mdb:DialogBehavior.Style>
                <Style BasedOn="{StaticResource DialogStyleKey}"
                       TargetType="{x:Type Window}">
                    <Setter Property="Title"
                            Value="{Binding Content.Title, RelativeSource={x:Static RelativeSource.Self}}"/>
                </Style>
            </mdb:DialogBehavior.Style>
        </mdb:DialogBehavior>
    </i:Interaction.Behaviors>

    <StackPanel Margin="10"
                Style="{StaticResource VerticalStackPanelStyle}">
        <StackPanel Style="{StaticResource HorizontalStackPanelStyle}">
            <ComboBox DisplayMemberPath="Title"
                      ItemsSource="{Binding Works}"
                      MinWidth="150"
                      SelectedValue="{Binding LastWorkNumber, Mode=TwoWay}"
                      SelectedValuePath="Number"
                      VerticalAlignment="Center">
                <ComboBox.ItemContainerStyle>
                    <Style BasedOn="{StaticResource {x:Type ComboBoxItem}}"
                           TargetType="{x:Type ComboBoxItem}">
                        <Style.Setters>
                            <Setter Property="IsEnabled"
                                    Value="{Binding IsSupported}"/>
                        </Style.Setters>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Title}"
                                         Value="">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                                            <Separator Style="{x:Null}"/>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ComboBox.ItemContainerStyle>
            </ComboBox>
            <Separator/>
            <Label Content="{Binding SupportedVersions}"/>
        </StackPanel>

        <Separator/>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="250"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>

            <Grid.Resources>
                <Style BasedOn="{StaticResource {x:Type Button}}"
                       TargetType="{x:Type Button}">
                    <Setter Property="Margin"
                            Value="5,2,0,2"/>
                </Style>
                <Style BasedOn="{StaticResource {x:Type ListBox}}"
                       TargetType="{x:Type ListBox}">
                    <Setter Property="Margin"
                            Value="0,2"/>
                </Style>
                <Style BasedOn="{StaticResource {x:Type TextBox}}"
                       TargetType="{x:Type TextBox}">
                    <Setter Property="Margin"
                            Value="0,2"/>
                </Style>
            </Grid.Resources>

            <Label Grid.Column="0"
                   Grid.Row="0"
                   Content="スコア(_S):"
                   HorizontalAlignment="Left"
                   Target="{Binding ElementName=ScoreTextBox, Mode=OneWay}"
                   VerticalAlignment="Center"/>
            <TextBox x:Name="ScoreTextBox"
                     Grid.Column="1"
                     Grid.Row="0"
                     IsReadOnly="True"
                     Text="{Binding ScoreFile, UpdateSourceTrigger=PropertyChanged}"
                     VerticalAlignment="Center">
                <i:Interaction.Behaviors>
                    <b:UIElementDropBehavior DropCommand="{Binding DropScoreFileCommand}"
                                             PreviewDragEnterCommand="{Binding DraggingCommand}"
                                             PreviewDragOverCommand="{Binding DraggingCommand}"/>
                </i:Interaction.Behaviors>
            </TextBox>
            <Button Grid.Column="2"
                    Grid.Row="0"
                    Content="開く(_O)..."
                    VerticalAlignment="Center">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <a:OpenFileDialogAction Filter="{x:Static prop:Resources.fltScoreFile}"
                                                InitialDirectory="{Binding OpenScoreFileDialogInitialDirectory}"
                                                OkCommand="{Binding SelectScoreFileCommand}"
                                                Owner="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>

            <Label Grid.Column="0"
                   Grid.Row="1"
                   Content="ベストショット(_B):"
                   HorizontalAlignment="Left"
                   IsEnabled="{Binding CanHandleBestShot}"
                   Target="{Binding ElementName=BestShotTextBox, Mode=OneWay}"
                   VerticalAlignment="Center"/>
            <TextBox x:Name="BestShotTextBox"
                     Grid.Column="1"
                     Grid.Row="1"
                     IsEnabled="{Binding CanHandleBestShot}"
                     IsReadOnly="True"
                     Text="{Binding BestShotDirectory, UpdateSourceTrigger=PropertyChanged}"
                     VerticalAlignment="Center">
                <i:Interaction.Behaviors>
                    <b:UIElementDropBehavior DropCommand="{Binding DropBestShotDirectoryCommand}"
                                             PreviewDragEnterCommand="{Binding DraggingCommand}"
                                             PreviewDragOverCommand="{Binding DraggingCommand}"/>
                </i:Interaction.Behaviors>
            </TextBox>
            <Button Grid.Column="2"
                    Grid.Row="1"
                    Content="開く(_O)..."
                    IsEnabled="{Binding CanHandleBestShot}"
                    VerticalAlignment="Center">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <a:FolderBrowserDialogAction Description="{x:Static prop:Resources.msgSelectBestShotDirectory}"
                                                     OkCommand="{Binding SelectBestShotDirectoryCommand}"
                                                     Owner="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                                     SelectedPath="{Binding Text, ElementName=BestShotTextBox}"
                                                     ShowNewFolderButton="False"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>

            <Label Grid.Column="0"
                   Grid.Row="2"
                   Content="テンプレート(_T):"
                   HorizontalAlignment="Left"
                   Target="{Binding ElementName=TemplateListBox, Mode=OneWay}"
                   VerticalAlignment="Top"/>
            <ListBox x:Name="TemplateListBox"
                     Grid.Column="1"
                     Grid.Row="2"
                     ScrollViewer.HorizontalScrollBarVisibility="Visible"
                     ScrollViewer.VerticalScrollBarVisibility="Auto"
                     AllowDrop="True"
                     Height="100"
                     ItemsSource="{Binding TemplateFiles, Mode=TwoWay}"
                     SelectionMode="Multiple"
                     VerticalAlignment="Top">
                <i:Interaction.Behaviors>
                    <b:UIElementDropBehavior DropCommand="{Binding DropTemplateFilesCommand}"
                                             PreviewDragEnterCommand="{Binding DraggingCommand}"
                                             PreviewDragOverCommand="{Binding DraggingCommand}"/>
                </i:Interaction.Behaviors>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding TemplateFilesSelectionChangedCommand}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </ListBox>
            <StackPanel Grid.Column="2"
                        Grid.Row="2">
                <Button Content="追加(_A)...">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <a:OpenFileDialogAction Filter="{x:Static prop:Resources.fltTemplateFile}"
                                                    InitialDirectory="{Binding OpenTemplateFilesDialogInitialDirectory}"
                                                    Multiselect="True"
                                                    OkCommand="{Binding AddTemplateFilesCommand}"
                                                    Owner="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
                <Button Command="{Binding DeleteTemplateFilesCommand}"
                        CommandParameter="{Binding SelectedItems, ElementName=TemplateListBox}"
                        Content="削除(_C)"/>
                <Button Command="{Binding DeleteAllTemplateFilesCommand}"
                        Content="全て削除(_L)"/>
            </StackPanel>

            <Label Grid.Column="0"
                   Grid.Row="3"
                   Content="出力先(_O):"
                   HorizontalAlignment="Left"
                   Target="{Binding ElementName=OutputTextBox, Mode=OneWay}"
                   VerticalAlignment="Center"/>
            <TextBox x:Name="OutputTextBox"
                     Grid.Column="1"
                     Grid.Row="3"
                     IsReadOnly="True"
                     Text="{Binding OutputDirectory, UpdateSourceTrigger=PropertyChanged}"
                     VerticalAlignment="Center">
                <i:Interaction.Behaviors>
                    <b:UIElementDropBehavior DropCommand="{Binding DropOutputDirectoryCommand}"
                                             PreviewDragEnterCommand="{Binding DraggingCommand}"
                                             PreviewDragOverCommand="{Binding DraggingCommand}"/>
                </i:Interaction.Behaviors>
            </TextBox>
            <Button Grid.Column="2"
                    Grid.Row="3"
                    Content="開く(_O)..."
                    VerticalAlignment="Center">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <a:FolderBrowserDialogAction Description="{x:Static prop:Resources.msgSelectOutputDirectory}"
                                                     OkCommand="{Binding SelectOutputDirectoryCommand}"
                                                     Owner="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                                     SelectedPath="{Binding Text, ElementName=OutputTextBox}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>

            <Label Grid.Column="0"
                   Grid.Row="4"
                   Content="画像出力先(_I):"
                   HorizontalAlignment="Left"
                   IsEnabled="{Binding CanHandleBestShot}"
                   Target="{Binding ElementName=ImageOutputTextBox, Mode=OneWay}"
                   VerticalAlignment="Center"/>
            <TextBox x:Name="ImageOutputTextBox"
                     Grid.Column="1"
                     Grid.Row="4"
                     IsEnabled="{Binding CanHandleBestShot}"
                     Text="{Binding ImageOutputDirectory, UpdateSourceTrigger=PropertyChanged}"
                     VerticalAlignment="Center"/>
            <CheckBox Grid.Column="1"
                      Grid.ColumnSpan="2"
                      Grid.Row="5"
                      Content="未挑戦のスペルカード名を出力しない(_H)"
                      IsChecked="{Binding HidesUntriedCards}"
                      IsEnabled="{Binding CanReplaceCardNames}"/>
        </Grid>

        <Separator/>

        <Button Command="{Binding ConvertCommand}"
                Content="変換(_V)"
                HorizontalAlignment="Center"
                IsDefault="True"
                MinWidth="100"/>

        <Separator/>

        <TextBox AllowDrop="False"
                 FontSize="10"
                 Height="70"
                 IsReadOnly="True"
                 IsUndoEnabled="False"
                 Text="{Binding Log, NotifyOnTargetUpdated=True}"
                 TextWrapping="Wrap"
                 VerticalScrollBarVisibility="Visible">
            <i:Interaction.Behaviors>
                <b:TextBoxBaseScrollBehavior AutoScrollToEnd="True"/>
            </i:Interaction.Behaviors>
        </TextBox>

        <Separator/>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="1"
                        Style="{StaticResource HorizontalStackPanelStyle}">
                <Button Command="{Binding OpenSettingWindowCommand}"
                        Content="設定(_S)..."/>
                <Separator/>
                <Button Command="{Binding OpenAboutWindowCommand}"
                        Content="_About..."/>
            </StackPanel>
        </Grid>
    </StackPanel>
</Window>
